<?php
/**
 * Représente une liste de questions de QCM
 *
 * @author Kévin Fauconnet (09/08/2013)
 */
 
class QCM_List extends SimpleModel {
	
	public $id_list;
	public $libelle;
	public $id_user;
	public $shared;
	public $last_update;
	
	public $user;
	
	
	public function sqltable() { return "qcm_lists"; }
	
	public function schema() { return array(
		'id_list' 				=> array('primarykey' => true, 'type' => 'int'),
		'libelle' 				=> 'string(128)',
		'id_user'				=> 'int',
		'shared' 				=> 'boolean',
		'last_update' 			=> 'datetime'
	);}
	
	/**
	 * Crée un nouvel objet
	 */
	public function __construct($param = array()) {
		$this->id_list = 0;
		$this->libelle = "";
		$this->id_user = 0;
		$this->shared = true;
		$this->last_update = null;
		
		$this->user = null;
		
		$this->init($param);
	}
	
	/**
	 * Remplit l'objet depuis les résultats d'un PDOStatement
	 */
	public function fromStatement($rowFetched, $st) {
		parent::fromStatement($rowFetched);
		
		if (!empty($rowFetched['email'])) {
			require_once(CLASS_PATH.'user.class.php');
			$u = new User();
			$u->init($st);
			$this->user = $u;
		}
	}
	
	/**
	 * Sauvegarde l'objet, et met à jour l'attribut last_update
	 */
	public function save($options = array()) {
		$this->last_update = date('d/m/Y H:i:s');
		$res = parent::save($options);
		return $res;
	}

}
?>